#include <cstring>
#include <gtest/gtest.h>
#include "l1ioapi.h"

TEST(l1ioapi, t1){
  l1api::pipe p1("pipe1");
  EXPECT_EQ(0, p1.open());
  const char *msg1 = "This is msg1";
  EXPECT_EQ(12, p1.write(msg1, strlen(msg1)));

  char rcvMsg[4096];
  memset(rcvMsg, 0, sizeof(rcvMsg));
  EXPECT_EQ(12, p1.read(&(rcvMsg[0]), sizeof(rcvMsg)));
  ASSERT_STREQ("This is msg1", rcvMsg);

}

TEST(l1ioapi, t_4char){
  l1api::pipe p1("pipe1");
  EXPECT_EQ(0, p1.open());
  const char *msg1 = "This is msg1";
  EXPECT_EQ(12, p1.write(msg1, strlen(msg1)));

  char rcvMsg[4];
  memset(rcvMsg, 0, sizeof(rcvMsg));
  EXPECT_EQ(4, p1.read(&(rcvMsg[0]), sizeof(rcvMsg)));
  ASSERT_STREQ("This", rcvMsg);
  EXPECT_EQ(0, p1.close());

}
